<?php

namespace app\model;

use think\Model;

/**
 * @property string $method
 * @property string $url
 * @property string $ip
 * @property int $uid
 * @property string $request
 * @property string $response
 * @property string $header
 * @property int $code
 * @property float $time
 */

class ApiLogDao extends Model
{
    protected $table = 'api_log';

    protected $autoWriteTimestamp = 'datetime';
    protected $createTime = 'create_at';
    protected $updateTime = 'update_at';

    protected $dateFormat = 'Y-m-d H:i:s';

    public function setRequestAttr($value)
    {
        $value=is_string($value)? $value : json_encode($value,JSON_UNESCAPED_UNICODE);
        return sub_str($value,  3000);
    }

    public function setResponseAttr($value)
    {
        $rs = is_string($value) ? $value : json_encode($value, JSON_UNESCAPED_UNICODE);
        return sub_str($rs, 8000);
    }

    public function setHeaderAttr($value)
    {
        return json_encode($value);
    }
}